 package com.example.marqueen;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

 public class MainActivity extends AppCompatActivity {

     private List<String> mList;

     @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        GridView gridView = (GridView) findViewById(R.id.gridview);

         mList = new ArrayList<>();
        for(int i = 0; i <20;i++){
            mList.add("因为刚好遇见你"+i*100+"留下足迹才美丽");
        }

        gridView.setAdapter(new gridviewAdapter());
    }

     class gridviewAdapter extends BaseAdapter{

         @Override
         public int getCount() {
             return mList==null?0:mList.size();
         }

         @Override
         public Object getItem(int position) {
             return mList.get(position);
         }

         @Override
         public long getItemId(int position) {
             return position;
         }

         @Override
         public View getView(int position, View convertView, ViewGroup parent) {

             if (convertView==null){
                 ViewHolder viewHolder=new ViewHolder();
                 convertView = View.inflate(MainActivity.this,R.layout.textview_item,null);
                 viewHolder.mTextView= (TextView) convertView.findViewById(R.id.focus_textview);
                 convertView.setTag(viewHolder);
             }else {
                 ViewHolder holder = (ViewHolder) convertView.getTag();
             }

             ViewHolder tag = (ViewHolder) convertView.getTag();
             tag.mTextView.setText(mList.get(position));
             tag.mTextView.setTextSize(20);
             tag.mTextView.setTextColor(Color.RED);

             return convertView;
         }
     }

     class ViewHolder{
         private TextView mTextView;
     }
}
